<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <script type="text/javascript" src="js/vue-2.6.12.js"></script>
    <script type="text/javascript" src="js/myajax.js"></script>
</head>
<body>
<div id="app">
    <form action="#" @submit.prevent="handelSubmit">
        <table>
            <tr>
                <td>
                    用户名：
                </td>
                <td>
                    <input type="text" v-model="userName"/>
                </td>
            </tr>
            <tr>
                <td>
                    密码：
                </td>
                <td>
                    <input type="password" v-model="password"/>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="登录">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <span>{{msg}}</span>
                </td>
            </tr>
        </table>

    </form>
</div>

<script>
    const vm = new Vue({
        el:"#app",
        data:{
            msg:"",
            userName:"",
            password:""
        },
        methods:{
            handelSubmit(){
                let url="/test/user/login";
                let data=`userName=${this.userName}&password=${this.password}`;
                let type="post";
                myAjax(url,data,type,(result)=>{
                    if(result=="login up"){
                        location.href="productList.html";
                    }else{
                        this.msg=result;
                    }
                })
            }
        }
    })
</script>

</body>
</html>